#include "HeaderSection.h"
#include <QtWidgets>
#include "DebugTool.h"

QString units= "千百十亿千百十万千百十元角分";

HeaderSection::HeaderSection(QString title,QWidget *parent)
    : QWidget(parent)
    ,title (title)
{
    this->setFixedSize (188,50);
    this->setAttribute (Qt::WA_StyledBackground);
}

void HeaderSection::paintEvent(QPaintEvent */*event*/)
{
    QPainter painter(this);

    QRect txtRect = this->fontMetrics ().boundingRect (title);

    painter.drawText ( ( width () - txtRect.width ()     ) /2,
                       ( height()/2 + txtRect.height() ) / 2 ,title);

    painter.drawLine (0,25,188,25);

    int charWidth = 13;


    for (int i = 1; i < 14; ++i) {

        painter.setPen(QColor(161, 230, 211));  // 浅绿色

        if(i%4==0){
            painter.setPen (Qt::gray);
        }

        if(i == 12){
            painter.setPen (QColor(255, 37, 37)); // 红色
        }

        painter.drawLine(  i * (charWidth)+2, 25, i * (charWidth)+2, height());

    }
    QFont f = font ();
    f.setPixelSize (13);
    painter.setPen (Qt::black);
    painter.setFont (f);
    painter.drawText (4,45,units);
}
